<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
	<head>
<jsp:include page="../inc.jsp"></jsp:include>		
<script type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" charset="utf-8">
	var datagrid;
	var auth = "${auths}";
	var buttons = [];
	var tyid = "${sessionInfo.type}";
	$(function() {
	    $('form input').bind('keyup', function(event) {/* 增加回车提交功能 */
			if (event.keyCode == '13') {
				datagrid.datagrid('load', sy.serializeObject($('#searchForm')));
			}
		});
		
		datagrid = $('#datagrid').datagrid({
			url : 'salelistAction!noAuth_salelistItemDatagrid.html',
			title : '销售明细列表',
			iconCls : 'icon-save',	
			pagination : true,
			pagePosition : 'bottom',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40 ],
			fit : true,
			fitColumns : false,
			nowrap : false,
			border : false,
			idField : 'id',
			sortName : 'name',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			singleSelect : true,
			frozenColumns : [ [ {
				title : '编号',
				field : 'id',
				width : 150,
				hidden : true
			},{
				title : '商品条码',
				field : 'gbarcode',
				width : 130,
				sortable : true,
			},{
				title : '款号',
				field : 'gtype',
				width : 80,
				align:'center',
				sortable : true,
			}]],
			columns : [ [ {
				title : '商品名称',
				field : 'gname',
				width : 100,
				align:'center',
				sortable : true,
			},  {
				title : '品牌ID',
				field : 'bid',
				width : 80,
				align :'center',
				hidden :true
			},  {
				title : '品牌',
				field : 'bname',
				width : 80,
				align:'center'
			}, {
				title : '商品类别Id',
				field : 'gtid',
				width : 70,
				align:'center',
				hidden :true
			}, {
				title : '商品类别',
				field : 'gtname',
				width : 70,
				align:'center'
			}, {
				title : '颜色',
				field : 'gcolor',
				width : 60,
				align:'center'
			}, {
				title : '尺码',
				field : 'gsize',
				width : 50,
				align:'center',
				sortable : true,
			}
// 			,{
// 				title : '单位',
// 				field : 'unit',
// 				width : 60,
// 				align:'center'
// 			}
// 			, {
// 				title : '吊牌价',
// 				field : 'showPrice',
// 				width : 60,
// 				align:'center'
// 			}
			, {
				title : '吊牌价',
				field : 'showPrice',
				width : 50,
				align:'center',
				sortable : true,
			}, {
				title : '进价',
				field : 'buyPrice',
				width : 60,
				align:'center',
				sortable : true,
			}, {
				title : '销售数量',
				field : 'zxssl',//number
				width : 60,
				align:'center',
				sortable : true,
			}, {
				title : '退货数量',
				field : 'zthsl',//number
				width : 60,
				align:'center',
// 				sortable : true,
			}, {
				title : '实际销售数量',
				field : 'xssl',//number
				width : 80,
				align:'center',
// 				sortable : true,
			},{
				title : '销售金额',
				field : 'xsje',//total
				width : 80,
				align:'center',
// 				sortable : true,
			},{
				title : '仓库Id',
				field : 'rid',
				width : 100,
				hidden : true,
				align:'center',
			},{
				title : '仓库',
				field : 'rname',
				width : 80,
				align:'center'
			}] ],
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});
		if(tyid==5||tyid==1){
			$('#datagrid').datagrid('showColumn','buyPrice')
		}else{
			$("#cbje").hide();
			$('#datagrid').datagrid('hideColumn','buyPrice')
		}
		
		var gtid0 = $('#searchForm').find('input[name=gtid]');
		var gtid0Combobox = gtid0.combobox({
			url : '${pageContext.request.contextPath}/spgl/goodsTypeAction!noAuth_combobox.html',
			valueField : 'id',
			textField : 'name',
			multiple : false,
			editable : true,
		});
		
		var bid0 = $('#searchForm').find('input[name=bid]');
		var bid0Combobox = bid0.combobox({
			url : '${pageContext.request.contextPath}/spgl/brandAction!noAuth_combobox.html',
			valueField : 'id',
			textField : 'name',
			multiple : false,
			editable : true,
			onLoadSuccess : function() {
				parent.$.messager.progress('close');
			}
		});
		
		_search();
		
		var rid0 = $('#searchForm').find('input[name=rid]');
		var rid0Combobox = rid0.combobox({
			url : '${pageContext.request.contextPath}/rkgl/repertoryAction!noAuth_combobox.html',
			valueField : 'id',
			textField : 'name',
			multiple : false,
			editable : true,
			onLoadSuccess : function() {
				if('${sessionInfo.repertoryIds}'!=null&&'${sessionInfo.repertoryIds}'!='null'){
					rid0.combobox('setValue','${sessionInfo.repertoryIds}');
				}
				parent.$.messager.progress('close');
			}
		});

	});

	function _search() {
		datagrid.datagrid('load', sy.serializeObject($('#searchForm')));
		$('#searchForm').form('submit', {
			url : '${pageContext.request.contextPath}/xsgl/salelistAction!noAuth_saleTotal.html',
			type : "POST",
			success : function(d){
				var json = $.parseJSON(d);
				$('#xszje').html((json.xszje).toFixed(2));
				$('#xszsl').html((json.xszsl));
				$('#yhzje').html((json.yhzje).toFixed(2));
				$('#lr').html((json.lr).toFixed(2));
				$('#cb').html((json.cb).toFixed(2));
				$('#thzsl').html(json.thzsl);
			}
		});
	}
	
	function cleanSearch() {
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
		_search();
	}
</script>
	</head>
	<body class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false,title:'搜索条件'"
			style="height: 112px; overflow: hidden;">
			<form id="searchForm">
				<table class="tableForm datagrid-toolbar"
					style="width: 100%; height: 100%;">
					<tr>
						<th style="width: 80px;">商品条码</th>
						<td style="width: 140px;"><input name="gbarcode" style="width: 140px;" /></td>
						<th style="width: 80px;">款&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</th>
						<td style="width: 120px;"><input name="gtype" style="width: 120px;" /></td>
						<th style="width: 80px;">尺码</th>
						<td style="width: 120px;"><input name="gsize" style="width: 120px;" /></td>
						<th style="width: 80px;">开始时间</th>
						<td style="width: 120px;"><input name="beginDate" style="width: 120px;" onClick="WdatePicker()" /></td>
					</tr>
					<tr>
						<th>商品类别</th>
						<td><input name="gtid" style="width: 145px;" /></td>
						<th>所属仓库</th>
						<td><input name="rid" style="width: 125px;" /></td>
						<th>品牌</th>
						<td><input name="bid" style="width: 125px;" /></td>
						<th>结束时间</th>
						<td><input name="endDate" style="width: 120px;" onClick="WdatePicker()" /></td>
					</tr>
					<tr>
						<td colspan="8" align="right" style="text-align:center">
							<a href="javascript:void(0);" class="easyui-linkbutton"
								onclick="_search();">搜索</a><a href="javascript:void(0);"
								class="easyui-linkbutton" onclick="cleanSearch();">取消</a>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false"
			style="overflow: hidden;">
			<table id="datagrid"></table>
		</div>
		<div data-options="region:'south',border:false"
		 align="right" 	style="background:#F2F2F2; height: 25px">
				实际销售总数量:<span id="xszsl"></span>	&nbsp;&nbsp;
				销售退货数量:<span id="thzsl"></span>	&nbsp;&nbsp;
				销售总金额:<span  id="xszje"></span>&nbsp;&nbsp;	
				优惠总金额:<span id="yhzje"></span>&nbsp;&nbsp;
				<span id="cbje">
				利润:<span id="lr" ></span>&nbsp;&nbsp; 
				成本:<span id="cb" ></span>&nbsp;
				</span>
		</div>
	</body>
</html>